package com.gidgabs.modules.api.service.impl;

import com.gidgabs.common.utils.Assist;
import com.gidgabs.common.utils.DeleteType;
import com.gidgabs.common.utils.LangUtil;
import com.gidgabs.common.utils.ReturnJson;
import com.gidgabs.dto.TbShoppingCarDto;
import com.gidgabs.modules.api.service.TbShoppingCarService;
import com.gidgabs.modules.dao.TbShoppingCarDao;
import com.gidgabs.modules.entity.TbProductEntity;
import com.gidgabs.modules.entity.TbShoppingCarEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class ShoppingCarServiceImpl implements TbShoppingCarService {
	@Autowired
	private TbShoppingCarDao shoppingCarDao;
	
	@Override
	public TbShoppingCarEntity queryObject(Integer id){
		return shoppingCarDao.queryObject(id);
	}
	
	@Override
	public List<TbShoppingCarEntity> queryList(Map<String, Object> map){
		return shoppingCarDao.queryList(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return shoppingCarDao.queryTotal(map);
	}
	
	@Override
	public void save(TbShoppingCarEntity shoppingCar){
		shoppingCarDao.save(shoppingCar);
	}
	
	@Override
	public void update(TbShoppingCarEntity shoppingCar){
		shoppingCarDao.update(shoppingCar);
	}
	
	@Override
	public void delete(Integer id){
		shoppingCarDao.delete(id);
	}
	
	@Override
	public void deleteBatch(Integer[] ids){
		shoppingCarDao.deleteBatch(ids);
	}

	@Override
	public ReturnJson<TbShoppingCarDto> queryShoppingCarList(Integer pageSize, Integer pageNo, Integer userId) {
		Assist assist = new Assist();
		//根据时间排序
		Assist.WhereOrder createTime = Assist.order("create_time", false);
		assist.andEq("user_id",userId);
		assist.setOrder(createTime);
		assist.setRowSize(pageSize);
		assist.setStartRow(LangUtil.firstLimit(pageSize, pageNo));
		List<TbShoppingCarEntity> tbShoppingCarEntities = shoppingCarDao.selectTbShoppingCar(assist);
		long count = shoppingCarDao.getTbShoppingCarRowCount(assist);
		List<TbShoppingCarDto> tbShoppingCarDtoList = new ArrayList<>();
		for (TbShoppingCarEntity tbShoppingCarEntity : tbShoppingCarEntities) {
			tbShoppingCarDtoList.add(tbShoppingCarEntity.toDto());
		}
		return ReturnJson.success("查询成功", tbShoppingCarDtoList, count, pageSize, pageNo);
	}

	@Override
	public TbShoppingCarEntity selectTbShoppingCarObjSingle(TbShoppingCarEntity obj) {
		return shoppingCarDao.selectTbShoppingCarObjSingle(obj);
	}

	@Override
	public int updateNotNullTbShoppingCarById(TbShoppingCarEntity enti) {
		return shoppingCarDao.updateNotNullTbShoppingCarById(enti);
	}

	@Override
	public TbShoppingCarEntity selectTbShoppingCarById(Integer id) {
		return shoppingCarDao.selectTbShoppingCarById(id);
	}

}
